/*
 * FileUtils.java
 *
 * Created on 01 March 2007, 16:31
 *
 * Copyright (C)
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

package com.grubby.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author A. HARMEL-LAW. E: andrew.harmel.law@gmail.com
 * @version 0.1
 */
public final class FileUtils {
    
    public static final Logger LOGGER
            = Logger.getLogger("com.grubby.utils.FileUtils");
    
    /* Log Strings */
    private static final String NULL_PARAMETER_EX = "A parameter was null: ";
    private static final String FILE_NOT_FOUND_EX = "File not Found Exception.";
    
    /** Private no args constructor */
    private FileUtils() { }
    
    /**
     * Common place to simpy create FileReaders from Files
     */
    public static FileReader getFileReader(final File file) {
        
        FileReader myReader;
        
        // Check file is not null
        if (file == null) {
            
            LOGGER.log(Level.WARNING, NULL_PARAMETER_EX + "file");
            throw new IllegalArgumentException(NULL_PARAMETER_EX + "file");
            
        } else {
            
            try {
                
                myReader =  new FileReader(file);
                
            } catch (FileNotFoundException e) {
                
                LOGGER.log(Level.WARNING, FILE_NOT_FOUND_EX);
                throw new RuntimeException(FILE_NOT_FOUND_EX, e);
                
            }
            
        }
        
        return myReader;
        
    }    
}